package com.xc.stock.domain.basic.service;

import java.math.BigDecimal;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSONObject;
import com.xc.stock.constant.AccountLogType;
import com.xc.stock.domain.basic.entity.Account;
import com.xc.stock.domain.basic.entity.AccountLog;
import com.xc.stock.domain.basic.factory.AccountLogFactory;
import com.xc.stock.domain.basic.repository.AccountLogRepository;
import com.xc.stock.dto.model.AccountOperParam;
import com.xc.stock.utils.SpringUtils;

import lombok.RequiredArgsConstructor;

/**
 * AccountLogService
 *
 * @author xlfd
 * @email xlfd@gmail.com
 * @created 2022/03/25
 */
@Service
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class AccountLogService {
	final AccountLogRepository repository;
	final AccountLogFactory factory;

	public AccountLog log(Integer actionId, AccountLogType accountLogType, Account account, BigDecimal amount, JSONObject pre,
			JSONObject after, AccountOperParam accountOperParam) {
		AccountLog log = factory.entity(actionId, accountLogType, account, amount, pre, after, accountOperParam);
		repository().save(log);
		return log;
	}
	
	public AccountLogRepository repository() {
		return repository;
	}

	public static AccountLogService of() {
		return SpringUtils.getBean(AccountLogService.class);
	}
}
